﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CheckList.Actions;
using Model;


namespace CheckList
{
    public partial class MainForm : Form{

        public static MainForm mainForm = null;
        public static string currentProject = string.Empty;
        private DataTable dtTree = null;
        private DataView dv = null;
        private string _saveFilePath = string.Empty;

        public MainForm(){
            mainForm = this;
            InitializeComponent();
            this.WindowState = FormWindowState.Maximized;
            CenterToScreen();
        }

        private void newProjectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!currentProject.Equals(string.Empty)) {
                MessageBox.Show("项目已经创建！","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                return;
            }
            if(new ProjectDetailsForm().ShowDialog() != DialogResult.OK) {
                return;
            }
            if(!currentProject.Equals(string.Empty)) {
                CreateProjectTree();
                
            }
            _saveFilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\CheckList Project\\"+currentProject+"\\"+currentProject+".cst";
        }

        private void AddImages(TreeNodeCollection node) {
            foreach (TreeNode treeNode in node) {
                if (treeNode.Nodes.Count != 0) 
                    AddImages(treeNode.Nodes);
                if (treeNode.Text.Equals(currentProject))
                {
                    treeNode.ImageIndex = 0;
                    treeNode.SelectedImageIndex = 0;
                }
                else if (treeNode.Text.Equals("危害分析小组"))
                {
                    treeNode.ImageIndex = 1;
                    treeNode.SelectedImageIndex = 1;
                }
                else if (treeNode.Text.Equals("PSI清单"))
                {
                    treeNode.ImageIndex = 2;
                    treeNode.SelectedImageIndex = 2;
                }
                else if (treeNode.Text.Equals("图纸清单"))
                {
                    treeNode.ImageIndex = 3;
                    treeNode.SelectedImageIndex = 3;
                }
                else if (treeNode.Text.Equals("审查清单"))
                {
                    treeNode.ImageIndex = 4;
                    treeNode.SelectedImageIndex = 4;
                }
                else if (treeNode.Parent.Text.Equals("审查清单"))
                {
                    treeNode.ImageIndex = 5;
                    treeNode.SelectedImageIndex = 5;
                }
            }
        }

        public TreeView ProjectTree{
            get { return tvProject; }
            set { tvProject = value; }
        }

        public TabControl TabPages{
            set { tcWorkSpace = value; }
            get { return tcWorkSpace; }
        }

        public string SaveFilePath {
            get { return _saveFilePath; }
            set { _saveFilePath = value; }
        }

       private void tvProject_AfterSelect(object sender, TreeViewEventArgs e){
            e.Node.Expand();
            TreeNode treeNode = tvProject.SelectedNode;

            if (treeNode.Text.Equals(currentProject))
                return;
            if (treeNode.Text.Equals("审查清单"))
            {
                return;
            }

            if (tcWorkSpace.TabPages.ContainsKey(treeNode.Text))
            {
                for (int i = 0; i < tcWorkSpace.TabPages.Count; i++)
                {
                    if (treeNode.Text.Equals(tcWorkSpace.TabPages[i].Name))
                    {
                        tcWorkSpace.SelectedIndex = i;
                        break;
                    }
                }
            }
//            else if (treeNode.Parent.Text.Equals("审查清单"))
//            {
//                TabPage tabPage = new TabPage(treeNode.Text);
//                tabPage.Name = treeNode.Text;
//                WhatIfWorkNode workNode = Program.Workspace.GetWorkNodeByNodeName(treeNode.Text);
//                WorkPage workPage = new WorkPage(workNode);
//                tabPage.Controls.Add(workPage);
//                workPage.Dock = DockStyle.Fill;
//                tcWorkSpace.TabPages.Add(tabPage);
//                tcWorkSpace.SelectedTab = tabPage;
//            }
            else if (treeNode.Text.Equals("图纸清单"))
            {
                TabPage tabPage = new TabPage(treeNode.Text);
                tabPage.Name = treeNode.Text;
                PidPage pidPage = new PidPage();
                tabPage.Controls.Add(pidPage);
                pidPage.Dock = DockStyle.Fill;
                tcWorkSpace.TabPages.Add(tabPage);
                tcWorkSpace.SelectedTab = tabPage;
            }
            else if (treeNode.Text.Equals("本质安全审查"))
            {
                TabPage tabPage = new TabPage(treeNode.Text);
                tabPage.Name = treeNode.Text;
                CheckListPage page = new CheckListPage(Program.Workspace.CheckListProject.IList, "本质安全审查");
                tabPage.Controls.Add(page);
                page.Dock = DockStyle.Fill;
                tcWorkSpace.TabPages.Add(tabPage);
                tcWorkSpace.SelectedTab = tabPage;
            }
            else if (treeNode.Text.Equals("人为因素审查"))
            {
                TabPage tabPage = new TabPage(treeNode.Text);
                tabPage.Name = treeNode.Text;
                CheckListPage page = new CheckListPage(Program.Workspace.CheckListProject.PList, "人为因素审查");
                tabPage.Controls.Add(page);
                page.Dock = DockStyle.Fill;
                tcWorkSpace.TabPages.Add(tabPage);
                tcWorkSpace.SelectedTab = tabPage;
            }
            else if (treeNode.Text.Equals("设施布置审查"))
            {
                TabPage tabPage = new TabPage(treeNode.Text);
                tabPage.Name = treeNode.Text;
                CheckListPage page = new CheckListPage(Program.Workspace.CheckListProject.FList, "设施布置审查");
                tabPage.Controls.Add(page);
                page.Dock = DockStyle.Fill;
                tcWorkSpace.TabPages.Add(tabPage);
                tcWorkSpace.SelectedTab = tabPage;
            }

            else  if (treeNode.Text.Equals("PSI清单"))
            {
               TabPage tabPage = new TabPage(treeNode.Text);
               tabPage.Name = treeNode.Text;
               PSIPage psiPage = new PSIPage();
               tabPage.Controls.Add(psiPage);
               psiPage.Dock = DockStyle.Fill;
               tcWorkSpace.TabPages.Add(tabPage);
               tcWorkSpace.SelectedTab = tabPage;
            }
            else if (treeNode.Text.Equals("危害分析小组"))
            {
                TabPage tabPage = new TabPage(treeNode.Text);
                tabPage.Name = treeNode.Text;
                HazopTeamPage3 hazopTeam = new HazopTeamPage3();
                tabPage.Controls.Add(hazopTeam);
                hazopTeam.Dock = DockStyle.Fill;
                tcWorkSpace.TabPages.Add(tabPage);
                tcWorkSpace.SelectedTab = tabPage;
            }
        }

        private void tcWorkSpace_MouseDown(object sender, MouseEventArgs e)
        {
            if(e.Button == MouseButtons.Right){
                for(int i = 0; i < tcWorkSpace.TabPages.Count; i++){
                    TabPage tabPage = tcWorkSpace.TabPages[i];
                    if(tcWorkSpace.GetTabRect(i).Contains(new Point(e.X,e.Y))){
                        tcWorkSpace.SelectedTab = tabPage;
                        tcWorkSpace.ContextMenuStrip = cmsTapPage;
                        break;
                    }
                } 
            }
        }

        private void tcWorkSpace_MouseLeave(object sender, EventArgs e){
            tcWorkSpace.ContextMenuStrip = null;
        }

        private void closeTabMenuItem_Click(object sender, EventArgs e){
            tcWorkSpace.SelectedTab.Dispose();
        }

        private void chemicalLibraryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChemicalLibraryForm chemicalLibraryForm = new ChemicalLibraryForm();
            chemicalLibraryForm.Show();
        }

        private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void CreateProjectTree()
        {
            CreateTable();
            CreateTree();
            ProjectTree.ImageList = _imgProject;
            AddImages(ProjectTree.Nodes);
        }

        private void CreateTable()
        {
            dtTree = new DataTable("ProjectTree");
            dtTree.Columns.Add(new DataColumn("TypeID", typeof(int)));
            dtTree.Columns.Add(new DataColumn("TypeName", typeof(string)));
            dtTree.Columns.Add(new DataColumn("TypeParentID", typeof(int)));

            dtTree.Rows.Add(new object[] { 1, currentProject, 0 });
            dtTree.Rows.Add(new object[] { 2, "危害分析小组", 1 });
            dtTree.Rows.Add(new object[] { 3, "PSI清单", 1 });
            dtTree.Rows.Add(new object[] { 4, "图纸清单", 1 });
            dtTree.Rows.Add(new object[] { 5, "审查清单", 1 });
            dtTree.Rows.Add(new object[] { 6, "本质安全审查", 5 });
            dtTree.Rows.Add(new object[] { 7, "人为因素审查", 5 });
            dtTree.Rows.Add(new object[] { 8, "设施布置审查", 5 });
        }

        private void CreateTree()
        {
            dv = dtTree.DefaultView;
            dv.Sort = "TypeParentID ASC";
            DataRowView[] arrDRV = dv.FindRows(0);
            if (arrDRV.Length == 0)
                return;
            TreeNode tnNew = null;
            foreach (DataRowView drv in arrDRV)
            {
                tnNew = MainForm.mainForm.ProjectTree.Nodes.Add(drv.Row["TypeName"].ToString());
                tnNew.Tag = drv.Row["TypeID"].ToString();
                tnNew.Name = drv.Row["TypeName"].ToString();
                CreateTreeNode(ref tnNew);
            }
        }

        private void CreateTreeNode(ref TreeNode tnParent)
        {
            DataRowView[] arrDRV = dv.FindRows(tnParent.Tag);
            if (arrDRV.Length == 0)
                return;
            TreeNode tnNew = null;
            foreach (DataRowView drv in arrDRV)
            {
                tnNew = tnParent.Nodes.Add(drv.Row["TypeName"].ToString());
                tnNew.Tag = drv.Row["TypeID"].ToString();
                tnNew.Name = drv.Row["TypeName"].ToString();
                CreateTreeNode(ref tnNew);
            }
        }

        private void addNodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
//            if(Program.Workspace.CheckListProject.PidList.Count == 0) {
//                MessageBox.Show("未发现PID列表，请先创建!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
//                return;
//            }
//            if (tvProject.SelectedNode != null){
//                AddNodeForm addNodeForm = new AddNodeForm();
//                addNodeForm.treeViewAddNode += new AddNodeForm.treeViewAddNodeEventHandler(addNodeForm_treeViewAddNode);
//                addNodeForm.ShowDialog();
//            }
        }

        private void addNodeForm_treeViewAddNode(string name, string pidList)
        {
//            TreeNode treeNode = new TreeNode(name);
//            treeNode.ImageIndex = 5;
//            treeNode.SelectedImageIndex = 5;
//            tvProject.SelectedNode.Nodes.Add(treeNode);
//
          //  tvProject.SelectedNode = treeNode;
//            TabPage tabPage = new TabPage(treeNode.Text);
//            tabPage.Name = treeNode.Text;
         //   WorkPage workPage = new WorkPage(Program.Workspace.project.ProjectDetails.ProjectName, name, DateTime.Today, GetTotalNodeCount().ToString(), pidList, Program.Workspace.project.ProjectDetails.ProjectDesc);
//            WhatIfWorkNode workNode = new WhatIfWorkNode(Program.Workspace.WhatIfProject.ProjectDetails.ProjectName,name,
//                                             GetTotalNodeCount().ToString(),Program.Workspace.WhatIfProject.ProjectDetails.TecUnit, DateTime.Today.ToShortDateString(), pidList);
//            WorkPage workPage = new WorkPage(workNode);
//            Program.Workspace.AddNewWorkNode(workNode);
//            tabPage.Controls.Add(workPage);
//            workPage.Dock = DockStyle.Fill;
//            tcWorkSpace.TabPages.Add(tabPage);
//            tcWorkSpace.SelectedTab = tabPage;
        }

        private int GetTotalNodeCount(){
            return tvProject.SelectedNode.Nodes.Count;
        }

        private void eventLibraryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EventLibraryForm eventForm = new EventLibraryForm();
            eventForm.Show();
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentProject.Equals(string.Empty))
            {
                MessageBox.Show("没有可保存的项目!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = "Project Data(*.cst)|";
            dialog.Title = "保存项目";
            dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            dialog.CheckPathExists = true;
            dialog.ValidateNames = true;
            dialog.AddExtension = true;
            dialog.DefaultExt = "cst";
            if (dialog.ShowDialog() == DialogResult.OK) {
                _saveFilePath = dialog.FileName;
                Program.Workspace.SaveProject(dialog.FileName);
                MessageBox.Show("项目保存成功");
            }
        }

        private void exportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentProject.Equals(string.Empty))
            {
                MessageBox.Show("没有导出的项目!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = "Excel 2003(*.xls)|*.xls|Excel 2007(*.xlsx)|*.xlsx|Excel 2010(*.xlsx)|*.xlsx";
            dialog.FilterIndex = 0;
            dialog.Title = "保存项目";
            dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            dialog.CheckPathExists = true;
            dialog.ValidateNames = true;
            dialog.AddExtension = true;
            dialog.DefaultExt = "xls";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                //Program.Workspace.ExportToExcel(dialog.FileName,Program.Workspace.project,Program.Workspace.GetHideColumns());

              //  MessageBox.Show("Excel数据成功导出!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                new ExcelExportAction(dialog.FileName,Program.Workspace.CheckListProject,Program.Workspace.GetHideColumns()).RunInProgress();
            }
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!currentProject.Equals(string.Empty)) {
                MessageBox.Show("项目已经创建，不能重复导入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Title = "打开项目文件";
            dialog.Filter = "Project Data(*.cst)|*.cst";
            dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            dialog.CheckPathExists = true;
            dialog.CheckFileExists = true;
            dialog.ValidateNames = true;
            CheckListProject project = null;
            if (dialog.ShowDialog() == DialogResult.OK){
                if (!dialog.FileName.Contains(".cst"))
                {
                    MessageBox.Show("不是CheckList项目文件，请重新导入!", "项目文件导入错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                _saveFilePath = dialog.FileName;
                project = Program.Workspace.OpenProject(dialog.FileName);
            }
            if (project != null){
                createTreeView(project);
            }
        }

        private void createTreeView(CheckListProject project)
        {
            currentProject = project.ProjectDetails.ProjectName;
           // ProjectTree.Nodes.Add(project.ProjectDetails.ProjectName);
           // TreeNode[] nodes = new TreeNode[];
        //    ProjectTree.Nodes[project.ProjectDetails.ProjectName].Nodes.AddRange();
            CreateProjectTree();
           //create all worknodes
            AddImages(ProjectTree.Nodes);
        }

        private void createNode_Click(object sender, EventArgs e) {
            if (currentProject.Equals(string.Empty)) {
                MessageBox.Show("项目为空，请首先创建项目!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            ProjectTree.SelectedNode = ProjectTree.Nodes[currentProject].Nodes["节点"];
            addNodeToolStripMenuItem_Click(sender, e);
        }

        private void newProject_Click(object sender, EventArgs e) {
            newProjectToolStripMenuItem_Click(sender, e);
        }

        private void openProject_Click(object sender, EventArgs e) {
            openToolStripMenuItem_Click(sender, e);
        }

        private void editColToolStripMenuItem_Click(object sender, EventArgs e){
            List<string> checkedCols = GetCheckedColumns();
            ColumnConfigForm configForm = new ColumnConfigForm(checkedCols);
            configForm.ShowDialog();
        }

//        void configForm_RefreshColumnEvent(List<string> col)
//        {
//            foreach (Control ctr in tcWorkSpace.SelectedTab.Controls)
//            {
//                if (ctr is WorkPage)
//                {
//                    WorkPage workPage = (WorkPage)ctr;
//                    DataGridView dataGridView = workPage.DgvWorkArea;
//                    foreach (DataGridViewColumn column in dataGridView.Columns)
//                    {
//                        if (col.Contains(column.HeaderText)){
//                            column.Visible = false;
//                        }
//                        else{
//                            column.Visible = true;
//                        }
//                    }
//                }
//            }
//        }

        private  List<string> GetCheckedColumns(){
            List<string> cols = new List<string>();
//            if (editColToolStripMenuItem.Enabled){
//                foreach (Control col in tcWorkSpace.SelectedTab.Controls){
//                    if(col is WorkPage){
//                        WorkPage workPage = (WorkPage) col;
//                        DataGridView dataGridView = workPage.DgvWorkArea;
//                        foreach (DataGridViewColumn column in dataGridView.Columns)
//                        {
//                            if (column.Visible){
//                                cols.Add(column.HeaderText);
//                            }
//                        }
//                    }
//                }
//            }
            List<string> hideColumns = Program.Workspace.GetHideColumns();
            foreach (string col in Program.Workspace.GetAllColumns())
            {
                if (!hideColumns.Contains(col)){
                    cols.Add(col);
                }
            }
            return cols;
        }

        private void saveAllStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentProject.Equals(string.Empty))
            {
                MessageBox.Show("没有可保存的项目!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (_saveFilePath.Equals(string.Empty))
            {
                MessageBox.Show("保存目录为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            foreach (TabPage page in tcWorkSpace.TabPages)
            {
                if (tcWorkSpace.TabPages.Count == 0)
                {
                    MessageBox.Show("没有可保存的页面");
                    return;
                }
                string tapName = page.Text;
                switch (tapName)
                {
                    case "危害分析小组": foreach (var control in page.Controls)
                        {
                            if (control.GetType() == typeof(HazopTeamPage3))
                            {
                                HazopTeamPage3 p = (HazopTeamPage3)control;
                                p.SaveWithoutRemider();
                            }
                        }
                        break;
                    case "PSI清单": foreach (var control in page.Controls)
                        {
                            if (control.GetType() == typeof(PSIPage))
                            {
                                PSIPage p = (PSIPage)control;
                                p.SaveWithoutRemider();
                            }
                        }
                        break;
                    case "图纸清单": foreach (var control in page.Controls)
                        {
                            if (control.GetType() == typeof(PidPage))
                            {
                                PidPage p = (PidPage)control;
                                p.SaveWithoutRemider();
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            Program.Workspace.SaveProject(_saveFilePath);
            MessageBox.Show("项目保存成功!");

        }

//        private void editGuideWordToolStripMenuItem_Click(object sender, EventArgs e)
//        {
//            GuideWordConfigForm configForm = new GuideWordConfigForm();
//            configForm.ShowDialog();
//            if (configForm.DialogResult ==DialogResult.OK) {
//                
//            }
//        }

        private void exportToExcel_Click(object sender, EventArgs e) {
            exportToolStripMenuItem_Click(sender, e);
        }

        private void saveAll_Click(object sender, EventArgs e){
            saveAllStripMenuItem_Click(sender, e);
        }

        private void tvProject_Click(object sender, EventArgs e) {
            if (ProjectTree.SelectedNode != null)
            {
                ProjectTree.SelectedNode.Expand();
                TreeNode treeNode = tvProject.SelectedNode;

                if (treeNode.Text.Equals(currentProject))
                    return;
                if (treeNode.Text.Equals("审查清单")){
                    return;
                }

                if (tcWorkSpace.TabPages.ContainsKey(treeNode.Text))
                {
                    for (int i = 0; i < tcWorkSpace.TabPages.Count; i++)
                    {
                        if (treeNode.Text.Equals(tcWorkSpace.TabPages[i].Name))
                        {
                            tcWorkSpace.SelectedIndex = i;
                            break;
                        }
                    }
                }
                else if (treeNode.Text.Equals("图纸清单"))
                {
                    TabPage tabPage = new TabPage(treeNode.Text);
                    tabPage.Name = treeNode.Text;
                    PidPage pidPage = new PidPage();
                    tabPage.Controls.Add(pidPage);
                    pidPage.Dock = DockStyle.Fill;
                    tcWorkSpace.TabPages.Add(tabPage);
                    tcWorkSpace.SelectedTab = tabPage;
                }

                else if (treeNode.Text.Equals("PSI清单"))
                {
                    TabPage tabPage = new TabPage(treeNode.Text);
                    tabPage.Name = treeNode.Text;
                    PSIPage psiPage = new PSIPage();
                    tabPage.Controls.Add(psiPage);
                    psiPage.Dock = DockStyle.Fill;
                    tcWorkSpace.TabPages.Add(tabPage);
                    tcWorkSpace.SelectedTab = tabPage;
                }
                else if (treeNode.Text.Equals("危害分析小组"))
                {
                    TabPage tabPage = new TabPage(treeNode.Text);
                    tabPage.Name = treeNode.Text;
                    HazopTeamPage3 hazopTeam = new HazopTeamPage3();
                    tabPage.Controls.Add(hazopTeam);
                    hazopTeam.Dock = DockStyle.Fill;
                    tcWorkSpace.TabPages.Add(tabPage);
                    tcWorkSpace.SelectedTab = tabPage;
                }
                else if (treeNode.Text.Equals("本质安全审查"))
                {
                    TabPage tabPage = new TabPage(treeNode.Text);
                    tabPage.Name = treeNode.Text;
                    CheckListPage page = new CheckListPage(Program.Workspace.CheckListProject.IList, "本质安全审查");
                    tabPage.Controls.Add(page);
                    page.Dock = DockStyle.Fill;
                    tcWorkSpace.TabPages.Add(tabPage);
                    tcWorkSpace.SelectedTab = tabPage;
                }
                else if (treeNode.Text.Equals("人为因素审查"))
                {
                    TabPage tabPage = new TabPage(treeNode.Text);
                    tabPage.Name = treeNode.Text;
                    CheckListPage page = new CheckListPage(Program.Workspace.CheckListProject.PList, "人为因素审查");
                    tabPage.Controls.Add(page);
                    page.Dock = DockStyle.Fill;
                    tcWorkSpace.TabPages.Add(tabPage);
                    tcWorkSpace.SelectedTab = tabPage;
                }
                else if (treeNode.Text.Equals("设施布置审查"))
                {
                    TabPage tabPage = new TabPage(treeNode.Text);
                    tabPage.Name = treeNode.Text;
                    CheckListPage page = new CheckListPage(Program.Workspace.CheckListProject.FList, "设施布置审查");
                    tabPage.Controls.Add(page);
                    page.Dock = DockStyle.Fill;
                    tcWorkSpace.TabPages.Add(tabPage);
                    tcWorkSpace.SelectedTab = tabPage;
                }
            }  
        }

        private void tvProject_MouseDown(object sender, MouseEventArgs e)
        {
            if ((sender as TreeView) != null) {
                ProjectTree.SelectedNode = ProjectTree.GetNodeAt(e.X, e.Y);
            }
            if (tcWorkSpace.SelectedTab == null)
            {
                return;
            }
            string name = tcWorkSpace.SelectedTab.Name;
        }



        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutForm aboutForm = new AboutForm();
            aboutForm.ShowDialog();
        }

        public TabControl TcWorkSpace{
            get { return tcWorkSpace; }
            set { tcWorkSpace = value; }
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!currentProject.Equals(string.Empty))
            {
                DialogResult dr = MessageBox.Show("项目是否需要保存？", "确认保存", MessageBoxButtons.YesNo);
                if (dr == DialogResult.Yes)
                {
                    saveAllStripMenuItem_Click(sender, e);
                }
            }
        }


    }
}
